package com.csweimei.rentmanagementtreasure.tenant.viewModel;

import android.app.Application;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.csweimei.rentmanagementtreasure.BuildConfig;
import com.csweimei.rentmanagementtreasure.WebActivity;
import com.csweimei.rentmanagementtreasure.http.Repository;
import com.csweimei.rentmanagementtreasure.viewModel.TitleVM;

import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.utils.ToastUtils;

public class AboutVM extends TitleVM {
    public AboutVM(@NonNull Application application) {
        super(application);
    }

    public ObservableField<String> userId = new ObservableField<>("");

    public ObservableField<String> verCode = new ObservableField<>("");

    public AboutVM(Application mApplication, Repository mRepository) {
        super(mApplication, mRepository);
        setTitleText("关于我们");
    }


    @Override
    public void onCreate() {
        super.onCreate();
        verCode.set("v"+BuildConfig.VERSION_NAME);
        if (model.isLogin()){
            userId.set(model.getLoginInfo().getData().getUser_id());
        }
    }

    public BindingCommand yhxy = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putString("flag", "YHXY");
            startActivity(WebActivity.class, bundle);
        }
    });

    public BindingCommand yszc = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putString("flag", "YSZC");
            startActivity(WebActivity.class, bundle);
        }
    });

    public BindingCommand beian = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("https://beian.miit.gov.cn"));
            mActivity.startActivity(intent);
        }
    });

    public BindingCommand copy = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            //获取剪贴板管理器：
            ClipboardManager cm = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
            // 创建普通字符型ClipData
            ClipData mClipData = ClipData.newPlainText("Label",userId.get());
            // 将ClipData内容放到系统剪贴板里。
            cm.setPrimaryClip(mClipData);
            ToastUtils.showShort("复制成功");
        }
    });

}
